package com.yanqu.road.server.cmd.activity.suoyao;

import com.yanqu.road.pb.activity.SuoYaoActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.suoyao.SuoYaoModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SUOYAO_ACTIVITY_DRAW_HIDE_BOX_FROM_CROSS, desc = "锁妖塔判断能否抽低价隐藏款  跨服返回")
public class SuoYaoDrawHideBoxFromCrossCmd extends AbstractCommand {

    String cost = "";
    boolean canHide = false;
    int drawIndex;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SuoYaoActivityProto.CrossSuoYaoDrawHideBoxRespMsg reqMsg = SuoYaoActivityProto.CrossSuoYaoDrawHideBoxRespMsg.parseFrom(packet.getBytes());
        ret = reqMsg.getRet();
        cost = reqMsg.getCost();
        drawIndex = reqMsg.getDrawIndex();
        if (ret == 0) {
            canHide = reqMsg.getIsHide();
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(SuoYaoModule.class).drawBoxFromCross(ret, cost, canHide, drawIndex);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            SuoYaoActivityProto.SuoYaoDrawBoxRespMsg.Builder builder = SuoYaoActivityProto.SuoYaoDrawBoxRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SUOYAO_ACTIVITY_DRAW_BOX, builder);
        }
    }
}
